{/* LAYOUT模板 */}
<layout name="layout"/>
{/* LAYOUT模板 */}
{/* import Js,Css */}
<css href="__PUBLIC__/css/admin/admin.css"/>
<js href="__PUBLIC__/js/admin/listTable.js"/>
<js href="__PUBLIC__/js/admin/js.validator.js"/>
<css href="__PUBLIC__/css/jquery-ui.css" />
<js href="__PUBLIC__/js/core/jquery-ui.1.10.4.js" />
<js href="__PUBLIC__/js/core/plugins.js"/>
{/* import js,css */}
<!-- [position] -->
	<include file="Template:position"/>
<!-- [position] -->
<div id="loading"><!--#加载条#--></div>

<div class="main-div">
	<form action="__URL__/add_cat_ok" method="post" name="theForm" enctype="multipart/form-data" onsubmit="return validate()">
	<table class="cat-list-table"	width="100%" id="general-table">
		<tbody>	
			<tr>
				<td class="label">分类名称:&nbsp;&nbsp;</td>
				<td>
					<input type="text" class="qs-input" name="cat_name" maxlength="20" value="" size="27"> 
					<font color="red">*</font>
				</td>
			</tr>
			<tr>
				<td class="label">上级分类:&nbsp;&nbsp;</td>
				<td>
					<select name="parent_id">
						<option value="0">顶级分类</option>
						<volist name="goodsCatList" id="goodsCat">
						<option value="{$goodsCat.cat_id}">{$goodsCat.cat_name}</option>
						</volist>      
					</select>
				</td>
			</tr>
			<tr id="measure_unit">
				<td class="label">数量单位:&nbsp;&nbsp;</td>
				<td>
					<input type="text" class="qs-input" name="measure_unit" value="" size="12">
				</td>
			</tr>
			<tr>
				<td class="label">排序:&nbsp;&nbsp;</td>
				<td>
					<input type="text" class="qs-input" name="sort_order" value="50" size="15">
				</td>
			</tr>
			<tr>
				<td class="label">是否显示:&nbsp;&nbsp;</td>
				<td>
					<input type="radio" name="is_show" value="1" checked="true"> 是          <input type="radio" name="is_show" value="0"> 否        </td>
			</tr>
			<tr>
				<td class="label">是否显示在导航栏:&nbsp;&nbsp;</td>
				<td>
					<input type="radio" name="show_in_nav" value="1"> 是          <input type="radio" name="show_in_nav" value="0" checked="true"> 否        </td>
			</tr>
			<tr class="hide">
				<td class="label">设置为首页推荐:&nbsp;&nbsp;</td>
				<td>
					<input type="checkbox" name="cat_recommend[]" value="1"> 精品          <input type="checkbox" name="cat_recommend[]" value="2"> 最新          <input type="checkbox" name="cat_recommend[]" value="3"> 热门        </td>
			</tr>
			<tr>
				<td class="label">
					<a href="javascript:showNotice('noticeFilterAttr');" title="点击此处查看提示信息">
						<img src="__PUBLIC__/image/admin/notice.gif" width="16" height="16" border="0" alt="您可以为每一个商品分类指定一个样式表文件。例如文件存放在 themes 目录下则输入：themes/style.css">
					</a>筛选属性:&nbsp;&nbsp;
				</td>
				<td>         
					<table width="100%" id="tbody-attr" align="center">
						<tbody>
							<tr>
								<td>   
									<a href="javascript:;" onclick="addFilterAttr(this)">[+]</a> 
									<select class="qs-input" onchange="changeCat(this)">
										<option value="0">请选择商品类型</option>
										<volist name="goodsTypeList" id="goodsType">
											<option value="{$goodsType.cat_id}">{$goodsType.cat_name}</option>
										</volist>
									</select>
									&nbsp;&nbsp;
									<select class="qs-input" name="filter_attr[]">
										<option value="0">请选择筛选属性</option>
									</select>
									<br>                   
								</td>
							</tr>
						</tbody>
					</table>
					<span class="notice-span" style="display:block" id="noticeFilterAttr">筛选属性可在前分类页面筛选商品</span>
				</td>
			</tr>
			<tr>
				<td class="label">
					<a href="javascript:showNotice('noticeGrade');" title="点击此处查看提示信息">
						<img src="__PUBLIC__/image/admin/notice.gif" width="16" height="16" border="0" alt="您可以为每一个商品分类指定一个样式表文件。例如文件存放在 themes 目录下则输入：themes/style.css">
					</a>价格区间个数:&nbsp;&nbsp;
				</td>
				<td>
					<input type="text" class="qs-input" name="grade" value="0" size="40"> <br>
					<span class="notice-span" style="display:block" id="noticeGrade">该选项表示该分类下商品最低价与最高价之间的划分的等级个数，填0表示不做分级，最多不能超过10个。</span>
				</td>
			</tr>
			<tr>
				<td class="label">
					<a href="javascript:showNotice('noticeGoodsSN');" title="点击此处查看提示信息">
						<img src="__PUBLIC__/image/admin/notice.gif" width="16" height="16" border="0" alt="您可以为每一个商品分类指定一个样式表文件。例如文件存放在 themes 目录下则输入：themes/style.css">
					</a>分类的样式表文件:&nbsp;&nbsp;
				</td>
				<td>
					<input type="text" class="qs-input" name="style" value="" size="40"> <br>
					<span class="notice-span" style="display:block" id="noticeGoodsSN">您可以为每一个商品分类指定一个样式表文件。例如文件存放在 themes 目录下则输入：themes/style.css</span>
				</td>
			</tr>
			<tr>
				<td class="label">关键字:&nbsp;&nbsp;</td>
				<td>
					<input type="text" class="qs-input" name="keywords" value="" size="50">
				</td>
			</tr>
			<tr>
				<td class="label">分类描述:&nbsp;&nbsp;</td>
				<td>
					<textarea class="qs-textarea" name="cat_desc" rows="6" cols="48"></textarea>
				</td>
			</tr>
		</tbody>
	</table>
    <div class="button-div">
        <input class="qs-btn" type="submit" value=" 确定 ">
        <input class="qs-btn" type="reset" value=" 重置 ">
    </div>
    <input type="hidden" name="act" value="insert">
    <input type="hidden" name="old_cat_name" value="">
    <input type="hidden" name="cat_id" value="">
  </form>
</div>

<script type="text/javascript">
           
	function changeCat(obj){
		var sel = window.ActiveXObject ? obj.parentNode.childNodes[4] : obj.parentNode.childNodes[5];
		var cat_id	=	obj.value;
		$.ajax({
			url:'__URL__/get_goodstype_attr',
			type:'post',
			dataType:'json',
			data:{cat_id:cat_id},
			beforeSend:function(){
				$('#loading').QLoading({text:'操作中...',modal:false,status:'open'});
			},
			success:function(msg){
				if(msg.data == '1'){
					sel.innerHTML	=	msg.info;
					$('#loading').QLoading({img:'happy',text:'操作成功',modal:false,status:'close',time:1.5});				
				}
				else{
					$('#loading').QLoading({img:'sad',text:'操作失败',modal:false,status:'close',time:1.5});
				}
			}
		});
	}

	/**
	 * 新增一个筛选属性
	 */	 
	function addFilterAttr(obj){
		var src = obj.parentNode.parentNode;
		var tbl = document.getElementById('tbody-attr');
		//var validator  = new Validator('theForm');
		var filterAttr = document.getElementsByName("filter_attr[]");

		if (filterAttr[filterAttr.length-1].selectedIndex == 0){
			/*捕捉error*/
			//validator.addErrorMsg(filter_attr_not_selected);
		}	  
		for (i = 0; i < filterAttr.length; i++){
			for (j = i + 1; j <filterAttr.length; j++){
				if (filterAttr.item(i).value == filterAttr.item(j).value){
				//validator.addErrorMsg(filter_attr_not_repeated);
				} 
			} 
		}
		var row  = tbl.insertRow(tbl.rows.length);
		var cell = row.insertCell(-1);
		cell.innerHTML = src.cells[0].innerHTML.replace(/(.*)(addFilterAttr)(.*)(\[)(\+)/i, "$1removeFilterAttr$3$4-");
		filterAttr[filterAttr.length-1].selectedIndex = 0;
	}

	/**
	 * 删除一个筛选属性
	 */
	function removeFilterAttr(obj){		
		var tbl = document.getElementById('tbody-attr');
		//var row = tbl.rowindex(obj.parentNode.parentNode);
		var row = obj.parentNode.parentNode.rowIndex;
		tbl.deleteRow(row);
	}	  

</script>
